<script setup>

import { ref ,onMounted} from 'vue'
import { useRouter } from 'vue-router'
import { addGoodsApi } from '../api/goods'

const router = useRouter()


const newname = ref('')
const newprice = ref('')
const addGoods = async () => {
  // 添加用户
  if (!newname.value&&!newprice.value) {
    alert('请输入!')
    return
  }
  //调用接口发送请求
  await addGoodsApi(newname.value, newprice.value)
  newname.value = ''
  newprice.value = ''
  alert('添加成功')
  router.push('/')
}
</script>

<template>
      产品名称:<input type="text" v-model="newname"> <br/>
      产品价格:<input type="text" v-model="newprice"><br/>
      <button @click="addGoods">添加</button>
</template>

<style scoped>


</style>
